package com.juzipi.thread.test;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;

/**
 * @Author juzipi
 * @Date 2021/6/15 20:04
 * @Info
 */
public class SleepTest1 {
    public static void main(String[] args) throws InterruptedException {
//        Date date = new Date(System.currentTimeMillis());//获取系统当前时间
//        while (true){
//            Thread.sleep(1000);
//            System.out.println(new SimpleDateFormat("HH:mm:ss").format(date));
//            date = new Date(System.currentTimeMillis());//更新时间
//        }
        Timer timer = new Timer();
        timer.schedule(new MyTask(),0,1000);


    }

    static class MyTask extends TimerTask{

        @Override
        public void run() {
            Date date = new Date();
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            System.out.println(simpleDateFormat.format(date));


        }
    }

    public static void counter() throws InterruptedException {
        int num = 10;

        while (true){
            Thread.sleep(1000);
            System.out.println(num--);
            if (num<=0){
                break;
            }
        }
    }

}
